#-*- coding: utf-8 -*-

uuid_mark = '@@##{uuid}##@@'
frame_start = 0
frame_end = 50 
frame_offset = 75 
start_frame_mark = '@@##{startFrame}##@@'
end_frame_mark = '@@##{endFrame}##@@'
subtitle_name_mark = '@@##{subtitle_name}##@@'
subtitle_name = 'subtitle'
display_name_mark = ''
content_mark = '@@##{str}##@@'
generator_id_mark = '@@##{generatoritemId}##@@'

subtitle_file = './subtitle.txt'

import uuid,re
from pubsource import *

#生成uuid
uuid_str = str(uuid.uuid1()) 
print(uuid_str)

##
#把字幕数组封装成pr图形文件格式
#返回格式字符串
##
def packSubtitleStr(_str_list):
    pass

##处理pr模板头部
def processPrHeadXml():
    return template_head.replace(subtitle_name_mark,subtitle_name).replace(uuid_mark,uuid_str)

##生成pr字幕图形文件xml文件
def genPrSubtitleFile(_str):
    pass

if __name__ == '__main__':
    generatorIndex = 0
    generatorContext = ''
    strList = open(subtitle_file,'r',encoding='utf-8').readlines()
    for line in strList:
        lineClear = line.replace('\r','').replace('\n','')
        if len(lineClear)>0:
            #print(lineClear)
            generatorContext = generatorContext + template_generate.replace(content_mark,lineClear)\
                .replace('@@##{strTitle}##@@',lineClear)\
                .replace(uuid_mark,uuid_str)\
                .replace(generator_id_mark,'generatorItem'+str(generatorIndex))\
                .replace(start_frame_mark,str(frame_start)+'.0')\
                .replace(end_frame_mark,str(frame_end)+'.0')
            frame_start += frame_offset
            frame_end += frame_offset
            generatorIndex += 1
    #print(generatorContext)
    subtitleXml =  processPrHeadXml() + generatorContext + template_tail
    subtitleFile = open('./%s.xml' % subtitle_name,'w',encoding='utf-8')
    subtitleFile.write(subtitleXml)
    subtitleFile.close()